<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
    <script>
            /* data elements */

//Comparing COMPANY  18:54:27
var new_COMPANY = new Array(

[ ' COMNO ', ' COMP_NAME ', ],
[])
var old_COMPANY = new Array(

[ ' COMNO ', ' COMP_NAME ', ],
[])

//Comparing COMPANY  18:54:27
var new_COMPANY_2 = new Array(

[ ' COMNO ', ' COMP_NAME ', ],
[])
var old_COMPANY_2 = new Array(

[ ' COMNO ', ' COMP_NAME ', ],
[])

//Comparing EMP  18:54:27
var new_EMP = new Array(

[ ' COMPANY ', ' EMPNO ', ' SNAME ', ],

[ '          1 ', '       1002 ', ' LINUS    ', ],
[ '          1 ', '       1003 ', ' LEMAN    ', ],
[ '          1 ', '       1004 ', '          ', ],
[])
var old_EMP = new Array(

[ ' COMPANY ', ' EMPNO ', ' SNAME ', ],

[ '          1 ', '       1002 ', ' ZHANG    ', ],
[ '          1 ', '       1003 ', '          ', ],
[ '          1 ', '       1004 ', ' 0        ', ],
[])

//Comparing DEPT  18:54:27
var new_DEPT = new Array(

[ ' COMPANY ', ' DPNAME ', ' DPNO ', ],

[ '          2 ', ' MARKET       ', '          2 ', ],
[ '          2 ', ' rd           ', '          3 ', ],
[ '          2 ', ' sell         ', '          1 ', ],
[])
var old_DEPT = new Array(

[ ' COMPANY ', ' DPNAME ', ' DPNO ', ],

[ '          2 ', ' RD           ', '          3 ', ],
[ '          2 ', ' market       ', '          2 ', ],
[])
    </script>
    <div id="mydiv">
    <h2 align="center"> Data Compare Report </h2>
      <script>
if(new_COMPANY.length<=2 && old_COMPANY.length<=2 ){
  document.write('Table COMPANY has no difference. <br>');
} else {
  document.write('Table COMPANY has some differences: <a href="javascript:print(new_COMPANY,old_COMPANY,\'new_COMPANY\', \'old_COMPANY\')"> view detail  </a> <br>');
}
if(new_COMPANY_2.length<=2 && old_COMPANY_2.length<=2 ){
  document.write('Table COMPANY_2 has no difference. <br>');
} else {
  document.write('Table COMPANY_2 has some differences: <a href="javascript:print(new_COMPANY_2,old_COMPANY_2,\'new_COMPANY_2\', \'old_COMPANY_2\')"> view detail  </a> <br>');
}
if(new_EMP.length<=2 && old_EMP.length<=2 ){
  document.write('Table EMP has no difference. <br>');
} else {
  document.write('Table EMP has some differences: <a href="javascript:print(new_EMP,old_EMP,\'new_EMP\', \'old_EMP\')"> view detail  </a> <br>');
}
if(new_DEPT.length<=2 && old_DEPT.length<=2 ){
  document.write('Table DEPT has no difference. <br>');
} else {
  document.write('Table DEPT has some differences: <a href="javascript:print(new_DEPT,old_DEPT,\'new_DEPT\', \'old_DEPT\')"> view detail  </a> <br>');
}
var maxrownum=500
      </script>
    </div>
    <div id="help">
    </div>
</body>
</html>

<script>
var PointX=0;PointY=0;
function ChangeValue(tname,i,j,value2) {
    var x=document.getElementById(tname).rows[i].cells;
    x[j+1].innerHTML=value2;
}
function savePoint() {    
    ev=window.event;
    if(typeof(ev)!='undefined'){
        PointX=ev.x;
        PointY=ev.y;
    }
}

function ChangeValues(table1, table2, tname1, tname2) {
    ev=window.event;
    if(typeof(ev)!='undefined'){
        if(ev.x!=PointX || ev.y != PointY) {
            return;
        }
    }
    reprint(table2, table1, tname2, tname1);
}
function SortAsc(table1,table2,tname1,tname2,col) {
    var r=confirm("Sort this column ascending?");
    if (r==true) {
        var head1=table1.shift();
        var head2=table2.shift();
        table1.sort( function(x,y) {
            return (x[col].localeCompare(y[col]))
        });
        table2.sort( function(x,y) {
            return (x[col].localeCompare(y[col]))
        });
        table1.unshift(head1);
        table2.unshift(head2);
        reprint(table1, table2, tname1, tname2);
    }
}
function MoveBtn(table1,table2,tname1,tname2,i) {
    var r=confirm("Move this record to bottom?");
    if (r==true) {
        var rec=table1.splice(i,1);
        table1.push(rec[0]);
        reprint(table1, table2, tname1, tname2);
    } 
}

function showHelp() {
    var helptext;
    helptext="<br>> Red cells means difference, view another value by move mouse over. <br>";
    helptext+="> By click anywhere of the table, you can shift between two tables globally. <br>";
    helptext+="> Move the record by click record's Number left, Sort by click column name. <br>";
    helptext+="> There are some problems when single quote(') appeared, check it manually.<br>";
    helptext+="<br> Open Source Software under GPLV3 licence.<br>";
    helptext+="Websit: http://code.google.com/p/transpring/source/browse/tools/dbcmp <br>";
    helptext+="<br>Contributors:<br>";
    helptext+="V1.1.0  20130816    leiminghuan@126.com    create<br>";
    helptext+="V2.0.1  20130823    leiminghuan@126.com    sorting, record moving, UI optimize<br>";
    helptext+="V2.2.0  20130903    leiminghuan@126.com    column's function, assigned table compare.<br>";
    var stat=document.getElementById("help");
    if(stat.innerHTML == "") {
        stat.innerHTML=helptext;
    }else {
        stat.innerHTML="";
    }
}
function print(table1, table2, tname1, tname2) {
    table1.pop();
    table2.pop();
    reprint(table1, table2, tname1, tname2);
}

function reprint(table1, table2, tname1, tname2) {
    var divtext, RecTmp1, RecTmp2;
    divtext='<a href = "javascript:location.reload()">Home</a>';
    if(typeof(maxrownum) != 'undefined') {
        if(table1.length >= maxrownum || table2.length >= maxrownum ) {
            divtext+='  <font color="#FF0000">(only shown first '+maxrownum+'records)</font>';
        }
    }
    var    td_attrs="";
    divtext+='<table id="'+tname1+'" border = "1" cellspacing = "0" style="border-collapse:collapse" ';
    divtext+='onmousedown="javascript:savePoint()" ';
    divtext+='onmouseup="javascript:ChangeValues('+tname1+','+tname2+',\''+tname1+'\',\''+tname2+'\')" >';
    for( var i=0; i<Math.max(table1.length,table2.length); i++) {
        if(typeof(table1[i]) == 'undefined') {
            RecTmp1=new Array();
        } else {
            RecTmp1=table1[i];
        }
        if(typeof(table2[i]) == 'undefined') {
            RecTmp2=new Array();
        } else {
            RecTmp2=table2[i];
        }
        divtext+="<tr>";
        for( var j=0; j<table1[0].length; j++) {
            if( j==0 ) {
                if(i == 0) {
                    divtext+='<td bgcolor="#c0c0c0" >'+(tname1+'..........').substring(0,12)+'</td>';
                } else {
                    divtext+='<td bgcolor="#F0F0F0" ';
                    divtext+='onmouseup="javascript:MoveBtn('+tname1+','+tname2+',\''+tname1+'\',\''+tname2+'\','+i+')"> ';
                    divtext+=i+'</td>';
                }
            }
            if(typeof(RecTmp1[j]) == 'undefined') {
                RecTmp1[j]="";
            }
            if(typeof(RecTmp2[j]) == 'undefined') {
                RecTmp2[j]="";
            }

            if(RecTmp1[j]!=RecTmp2[j]) {
                td_attrs='bgcolor="#FFAA00" ';
                if(Math.abs(RecTmp1[j]-RecTmp2[j])<0.1) {
                    td_attrs='bgcolor="#FDE0B3" ';
                }
                td_attrs += 'onmouseover="javascript:ChangeValue(\''+tname1+'\','+i+','+j+',\''+RecTmp2[j]+'\')" '+
                    'onmouseout ="javascript:ChangeValue(\''+tname1+'\','+i+','+j+',\''+RecTmp1[j]+'\')" ';

            }
            
            if(i==0) {
                td_attrs='bgcolor="#F0F0F0" ';
                td_attrs+='onmouseup="javascript:SortAsc('+tname1+','+tname2+',\''+tname1+'\',\''+tname2+'\','+j+')" ';
            }
            
            divtext+="<td "+td_attrs+">"+RecTmp1[j]+"</td>";
            td_attrs="";

        }
        divtext+="</tr>";
    }
    divtext+="</table>";
    divtext+='<br><a href = "javascript:showHelp()">Help</a>';
    document.getElementById("mydiv").innerHTML=divtext;
}
</script>

